package main

import (
	"fmt"
	"net/http"
)

// say hello to the world
func SayHello(w http.ResponseWriter, r *http.Request) {
	n, err := fmt.Fprintln(w, "hello world")
	if err != nil {
		fmt.Println("This response fair", err)
		return
	}
	fmt.Println(n)
	_, _ = w.Write([]byte("hello world"))
}

func HelloNexora(w http.ResponseWriter, r *http.Request) {
	_, _ = w.Write([]byte("hello nexora"))
}

func main() {

	// 12.9.注册一个处理函数
	serveMux := http.NewServeMux()
	serveMux.HandleFunc("/",SayHello)
	serveMux.HandleFunc("/nexora",HelloNexora) // 处理其他 url
	//2.设置监听的TCP地址并启动服务
	//参数1:TCP地址(IP+Port)
	//参数2:handler 创建新的*serveMux,不使用默认的
	err := http.ListenAndServe("0.0.0.0:8080", serveMux)
	if err != nil {
		fmt.Printf("http.ListenAndServe()函数执行错误,错误为:%v\n", err)
		return
	}

}
